ui.tweet = {};

ui.tweet.boxUpdate = function()
{
	var 
	text = $('#boxUpdateText').val(),
	status = $('#boxStatus');
	
	if( text )
	{
		status.text( i18n.get('sending') );
		
		ui.gestures.box.disableSend('#boxSend');
		
		ui.tweet.update( text, null, function( sucesso, result ){
			if( sucesso )
			{
				status.text( i18n.get('ok') );
				
				$('#box #content').hide();				
				$('#boxUpdateText').val('');				
				status.text('');
				
				ui.gestures.box.enableSend('#boxSend');
			}
			else
			{
				status.text( i18n.get('error') );
				
				ui.gestures.box.enableSend('#boxSend');
			}
		});
	}
	else
	{
		console.warn('ui.tweet.boxUpdate Fired with empty text!', text);
	}
};

ui.tweet.inlineUpdate = function( tid  )
{
	var
	reply = $('#replyText_' + tid),
	text = reply.val(),
	status = $('#replyStatus_' + tid);

	if( text )
	{	
		status.text( i18n.get('sending') );
		
		ui.gestures.box.disableSend('#replySend_'+tid);
		
		ui.tweet.update( text, tid, function( sucesso, result ){
			if( sucesso )
			{
				status.text( i18n.get('ok') );
				
				$('#reply_'+tid).fadeOut('slow', function(){
					$(this).remove();
				});
			}
			else
			{
				status.text( i18n.get('error') );
				
				ui.gestures.box.enableSend('#replySend_'+tid);
			}
		});
	}
	else
	{
		console.warn('ui.tweet.inlineUpdate Fired with empty text!', text, tid);
	}	
};

ui.tweet.update = function( text, in_reply_to, callback )
{
	twitter.update( text, in_reply_to , function( sucesso, result ){
		if( isFunction( callback ) )
		{
			callback( sucesso, result );
		}
	});
};


/*
ui.tweet.getConversation = function(tid, rid, timeline)
{
    var _Container = $('#twets_'+timeline+' #conversations_'+tid),
        _Visible   = _Container.css('display') == 'block' ? true : false,
        _Text      = $('#twets_'+timeline+' #in_reply_to_'+tid),
        _TxtBak    = _Text.attr('title');

    if(_Visible)
    {
        _Container.slideUp('fast');
        return;
    }

    if(!rid) return;

    _Text.addClass('loading-pulse').text(Traduz('loading'));

    Controller().Utils.Tweet.Conversation.init(rid, timeline, function(html, erro)
    {
        if(erro)
        {
            //_Text.text(Traduz('error'));
            _Text.removeClass('loading-pulse').text(_TxtBak);
            return;
        }

        try{
            ReplyCancel(tid, timeline);
        }
        catch(e){}
        _Container.empty();
        var hide_link = "<br /><a onclick='ui.tweet.getConversation("+tid+", null, \""+timeline+"\")' class='hide_link'>"+Traduz('hide')+"</a>";
        _Container.html(html+hide_link);
        _Container.slideDown('fast');
        Utils.ConversationsSets();
        _Text.removeClass('loading-pulse').text(_TxtBak);
    });
};
*/